package systemInformation;

import java.util.ArrayList;
import java.util.List;

import features.SNMPException;
import features.SNMPSession;
import features.SNMPValue;

public class StorageInfo {
	private static final String STORAGE_NAME_OID = ".1.3.6.1.2.1.25.2.3.1.3";

	private static final String STORAGE_TYPE_OID = ".1.3.6.1.2.1.25.2.3.1.2";

	private static final String SIZE_OID = ".1.3.6.1.2.1.25.2.3.1.5";

	private static final String USED_OID = ".1.3.6.1.2.1.25.2.3.1.6";

	private String storageName;

	private String storageType;

	private long size;

	private long used;

	public static List<StorageInfo> fromSession(SNMPSession session) throws SNMPException {
		List<StorageInfo> storages = new ArrayList<StorageInfo>();
		List<SNMPValue> lstName = session.getColumn(STORAGE_NAME_OID);
		List<SNMPValue> lstType = session.getColumn(STORAGE_TYPE_OID);
		List<SNMPValue> lstSize = session.getColumn(SIZE_OID);
		List<SNMPValue> lstUsed = session.getColumn(USED_OID);
		
		for (int i = 0; i < lstName.size(); i++) {
			StorageInfo info = new StorageInfo();
			
			info.setStorageName(lstName.get(i).toString());
			info.setStorageType(lstType.get(i).toString());
			info.setSize(lstSize.get(i).toLong());
			info.setUsed(lstUsed.get(i).toLong());
			
			storages.add(info);
		}
		
		return storages;
	}
	
	@Override
	public String toString() {
		return "StorageInfo [" + storageName + ", " + storageType + ", " + size + ", " + used + "]";
	}
	
	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + (int) (this.size ^ (this.size >>> 32));
		result = PRIME * result + ((this.storageName == null) ? 0 : this.storageName.hashCode());
		result = PRIME * result + ((this.storageType == null) ? 0 : this.storageType.hashCode());
		result = PRIME * result + (int) (this.used ^ (this.used >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final StorageInfo other = (StorageInfo) obj;
		if (this.size != other.size)
			return false;
		if (this.storageName == null) {
			if (other.storageName != null)
				return false;
		} else if (!this.storageName.equals(other.storageName))
			return false;
		if (this.storageType == null) {
			if (other.storageType != null)
				return false;
		} else if (!this.storageType.equals(other.storageType))
			return false;
		if (this.used != other.used)
			return false;
		return true;
	}

	public long getSize() {
		return this.size;
	}

	public void setSize(long free) {
		this.size = free;
	}

	public String getStorageName() {
		return this.storageName;
	}

	public void setStorageName(String storageName) {
		this.storageName = storageName;
	}

	public String getStorageType() {
		return this.storageType;
	}

	public void setStorageType(String storageType) {
		this.storageType = storageType;
	}

	public long getUsed() {
		return this.used;
	}

	public void setUsed(long used) {
		this.used = used;
	}
}
